﻿<section class="container-fluid" style="background-color: white;">
    <form class="form-horizontal m15_t" id="form">
        <div class="tab-content">
            <div class="tab-pane fade in active" id="home">
                <div class="form-group">
                    <label class="wd100 control-label">二维码格式:</label>
                    <div class="wd400 m15_l">
                        <label class="WdateFmtErr m5_t">材料名称#数量#批号1#批号2</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>二维码：</label>
                    <div class="wd400 m15_l">
                        <input class="form-control" type="text" name="barCode" maxlength="120" autocomplete="off" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"></label>
                    <div class="wd400 m15_l">
                        &nbsp;
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
@section footerScript{
    <script type="text/javascript">

        function save() {
            /*
            var obj = {
                "ProductName": "材料名称",
                "Quantity": 10000,
                "LotNo1": "2022-1",
                "LotNo2": "2022-2",
            }
            */
            

            var barCode = $("input[name='barCode']").val();

            if (Topro.Util.isNullOrEmptySpance(barCode)) {
                Topro.UI.Tip_danger("条码不能为空.")
                return false;
            }

            debugger;

            var obj = {};


            var arr = barCode.split("#");

            if (arr.length < 4) {
                Topro.UI.Tip_danger("二维码格式有误.")
                return false;
            }

            //物件编号
            obj.ProductName = arr[0];

            if (Topro.Util.isNullOrEmptySpance(obj.ProductName)) {
                Topro.UI.Tip_danger("物件编号不能为空.")
                return false;
            }


            //物料数量
            obj.Quantity = arr[1];

            if (Topro.Util.isNullOrEmptySpance(obj.Quantity)) {
                Topro.UI.Tip_danger("物料数量不能为空.")
                return false;
            }

            if (parseFloat(obj.Quantity) <= 0) {
                Topro.UI.Tip_danger("物料数量只能为正数.")
                return false;
            }

            var reg = /^(\-|\+)?\d+(\.\d+)?$/;
            if (!reg.test(obj.Quantity)) {
                Topro.UI.Tip_danger("物料数量只能为正数.")
                return false;
            }

            //批号1
            obj.LotNo1 = arr[2];

            if (Topro.Util.isNullOrEmptySpance(obj.LotNo1)) {
                Topro.UI.Tip_danger("批号1不能为空.")
                return false;
            }

            //批号2
            obj.LotNo2 = arr[3];

            Topro.UI.DialogOpener().addStockInItem(obj);
            Topro.UI.DialogOpener().Tip_success("操作成功！");
            Topro.UI.CloseDialog();
        }
    </script>
}